package com.kaishengit.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.kaishengit.entity.Employee;
import com.kaishengit.service.LoginService;

public class LoginServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String name = request.getParameter("name");
		String password = request.getParameter("password");
		System.out.println(name);
		Employee employee = new LoginService().findByName(name);
		
		if(employee == null) {
			response.sendRedirect("index.jspx?code=10002");
		} else {
			if(employee.getPassword().equals(password)) {
				HttpSession session =  request.getSession();
				session.setAttribute("loginUser", employee);
				request.getRequestDispatcher("project.jspx?_m=findProject").forward(request, response);
			}else {
				response.sendRedirect("index.jspx?code=10002");
			}
		}
	}
	
	
}
